package com.shenmazong.thread;

import lombok.SneakyThrows;

/**
 * @program: server-java-demo
 * @description: ThreadLiveApplication
 * @author: 亮子说编程
 * @create: 2020-10-20 20:55
 **/
public class ThreadLiveApplication implements Runnable {

    private volatile boolean flag = true;

    public void stop() {
        flag = false;
    }

    @SneakyThrows
    @Override
    public void run() {
        int idx = 0;
        while (flag) {
            System.out.println(Thread.currentThread().getName() + ",i=" + idx++);
            Thread.sleep(100);
        }
    }

    public static void main(String[] args) {
        ThreadLiveApplication threadLiveApplication = new ThreadLiveApplication();
        new Thread(threadLiveApplication).start();

        //
        try {
            Thread.sleep(1000*5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("停止吧........");
        threadLiveApplication.stop();
    }
}
